<!--
 * @description  : 案件-询问笔录文书
 * @descriptionDetail: 案件-询问笔录文书
 * @copyright    : 浙江烟草
 * @author       : dw
 * @create       : 2022-10-09 22:21:21
-->
<template>
  <view class="page">
    <!-- #ifdef H5-ONLY -->
    <theme-navbar :is-white="false" :title="navTitle" :custom-back="goBack" style="z-index: 99999">
      <view class="nav-right-icon" @click="printOrDown(state.canEdit)">
        {{ state.canEdit?'预览':'打印' }}
      </view>
    </theme-navbar>
    <!-- #endif -->
		<!-- #ifdef H5-WECHAT || H5-EMP -->
		<fab-button :content="state.canEdit?fContent:fContents" @fabtrigger="fabtrigger" />
		<!-- #endif -->
    <!-- 表单开始 -->
    <view class="main-content">
      <view style="width: calc(100% + 30px);">
        <form-section title="询问笔录"></form-section>
      </view>
      <u-form :label-position="labelPosition" :model="queryRecordForm" :error-type="errorType" :rules="rules" class="form-content" ref="uForm">
        <u-form-item
          label="询问开始时间"
          :required="isRequired"
          prop="askTimeS"
          :label-position="labelPosition"
          right-icon="arrow-right"
          ref="changeRefS"
        >
          <u-input
            placeholder="请输入开始时间"
            :disabled="true"
						:custom-style="pointerStyle"
            :clearable="false"
            v-model="queryRecordForm.askTimeS"
            @click="()=>{if(state.canEdit) clickDateBtn('isShowAskS')}"
          />
        </u-form-item>
        <u-form-item
          label="询问结束时间"
          :required="isRequired"
          prop="askTimeE"
          :label-position="labelPosition"
          right-icon="arrow-right"
          ref="changeRefE"
        >
          <u-input
            placeholder="请输入结束时间"
            :disabled="true"
						:custom-style="pointerStyle"
            :clearable="false"
            v-model="queryRecordForm.askTimeE"
            @click="()=>{if(state.canEdit) clickDateBtn('isShowAskE')}"
          />
        </u-form-item>
        <u-form-item label-width="auto" :border-bottom="false" label="询问地点" prop="handlingAddr" label-position="left" :required="isRequired">
          <u-icon
            slot="right"
            customPrefix="csbi-icon"
            name="moban"
            size="40"
            :color="$theme.u_type_primary"
            @click="tapFieldPress('handlingAddr')"
          ></u-icon>
        </u-form-item>
        <u-form-item label="">
          <u-input
            placeholder="请填写询问地点"
            :disabled="!state.canEdit"
            v-model="queryRecordForm.handlingAddr"
          />
        </u-form-item>
        <u-form-item prop="askPerson" ref="changeRefPerson">
          <view class="person-info">
            <view class="p-title">
              <view class="doc-sub-required">
                *
              </view>
              <view class="doc-sub-title">
                询问人
              </view>
              <view
                class="uicon-sty"
                :style="isCanClick?'pointer-events: none;':''"
                @click="()=>{if(state.canEdit) addUndertaker('aPer')}"
              >
                <u-icon name="plus-circle" :color="$theme.u_type_primary" size="40"></u-icon>
              </view>
            </view>
            <u-input placeholder="请输入" :disabled="true" :custom-style="pointerStyle" v-model="queryRecordForm.askPerson" />
          </view>
        </u-form-item>
        <u-form-item prop="recordPerson" ref="changeRefPerson">
          <view class="person-info">
            <view class="p-title">
              <view class="doc-sub-required">
                *
              </view>
              <view class="doc-sub-title">
                记录人
              </view>
              <view
                class="uicon-sty"
                :style="isCanClick?'pointer-events: none;':''"
                @click="()=>{if(state.canEdit) addUndertaker('rPer')}"
              >
                <u-icon name="plus-circle" :color="$theme.u_type_primary" size="40"></u-icon>
              </view>
            </view>
            <u-input placeholder="请输入" :disabled="true" :custom-style="pointerStyle" v-model="queryRecordForm.recordPerson" />
          </view>
        </u-form-item>
        <u-form-item label="被询问人" prop="byAskPsn" :label-position="labelPosition" :required="isRequired">
          <u-input
            placeholder="请选择被询问人"
            :disabled="!state.canEdit"
            :needValid="true"
            v-model="queryRecordForm.byAskPsn"
          />
          <u-icon name="man-add-fill" style="margin-top:-148rpx" :color="$theme.u_type_primary" size="40" @click="addAskPsn"></u-icon>
        </u-form-item>
        <u-form-item label="性别:" :label-position="labelPosition" :required="isRequired" prop="byAskSex">
          <dic-input
            :keyWord="$u.dic.DIC_KEYS.BSC_GENDDER"
            :dicCode="queryRecordForm.byAskSex"
            :border="ifborder"
            inputAlign="left"
            type="select"
            :select-open="
              dicSelectOpen('byAskSex', $u.dic.DIC_KEYS.BSC_GENDDER)
            "
            placeholder="请选择"
            v-model="queryRecordForm.byAskSexName"
            @changeInputModelData="
              (name) => {
                $set(queryRecordForm, 'byAskSexName', name);
              }
            "
            @click="
              showDic(
                $u.dic.DIC_KEYS.BSC_GENDDER,
                queryRecordForm.byAskSex,
                'byAskSex'
              )
            "
          />
        </u-form-item>
        <u-form-item
          label="年龄:"
          :label-position="labelPosition"
          :required="isRequired"
          prop="byAskAge"
        >
          <u-input
            placeholder="请输入年龄"
            :disabled="!state.canEdit"
            v-model="queryRecordForm.byAskAge"
          />
        </u-form-item>
        <u-form-item
          label="证件类型:"
          :label-position="labelPosition"
          :required="isRequired"
          prop="byAskIdType"
        >
          <dic-input
            :keyWord="$u.dic.DIC_KEYS.IDCARD_TYPE"
            :dicCode="queryRecordForm.byAskIdType"
            :border="ifborder"
            inputAlign="left"
            type="select"
            :select-open="
              dicSelectOpen('byAskIdType', $u.dic.DIC_KEYS.IDCARD_TYPE)
            "
            placeholder="请选择"
            v-model="queryRecordForm.byAskIdTypeName"
            @changeInputModelData="
              (name) => {
                $set(queryRecordForm, 'byAskIdTypeName', name);
              }
            "
            @click="
              showDic(
                $u.dic.DIC_KEYS.IDCARD_TYPE,
                queryRecordForm.byAskIdType,
                'byAskIdType'
              )
            "
          />
        </u-form-item>
        <u-form-item
          label="证件号码:"
          :label-position="labelPosition"
          :required="isRequired"
          prop="byAskIdNo"
        >
          <u-input
            placeholder="请输入证件号码"
            :disabled="!state.canEdit"
            v-model="queryRecordForm.byAskIdNo"
          />
        </u-form-item>
        <u-form-item
          label="民族:"
          :required="isRequired"
          :label-position="labelPosition"
          prop="byAskNation"
        >
          <dic-input
            :keyWord="$u.dic.DIC_KEYS.NATION_LIST"
            :dicCode="queryRecordForm.byAskNation"
            :border="ifborder"
            inputAlign="left"
            type="select"
            :select-open="dicSelectOpen('byAskNation',$u.dic.DIC_KEYS.NATION_LIST)"
            placeholder="请选择"
            v-model="queryRecordForm.byAskNationName"
            @changeInputModelData="(name)=>{$set(queryRecordForm, 'byAskNationName', name)}"
            @click="showDic($u.dic.DIC_KEYS.NATION_LIST,queryRecordForm.byAskNation,'byAskNation')"
          />
        </u-form-item>
        <u-form-item label="证件地址:" :label-position="labelPosition" :required="isRequired" prop="byAskHomeAddr">
          <u-input placeholder="请输入证件地址" :disabled="!state.canEdit" v-model="queryRecordForm.byAskHomeAddr" />
        </u-form-item>
        <u-form-item label="经营地址:" :label-position="labelPosition" :required="isRequired" prop="byAskAddr">
          <u-input placeholder="请输入经营地址" :disabled="!state.canEdit" v-model="queryRecordForm.byAskAddr" />
        </u-form-item>
        <u-form-item label="联系电话:" :label-position="labelPosition" :required="isRequired" prop="byAskPhone">
          <u-input placeholder="请输入联系电话" :disabled="!state.canEdit" v-model="queryRecordForm.byAskPhone" />
        </u-form-item>
        <u-form-item label-width="auto" :border-bottom="false" label-position="left" label="表明身份记录" prop="idRecordDesc" :required="isRequired">
          <u-icon
            slot="right"
            customPrefix="csbi-icon"
            name="moban"
            size="40"
            :color="$theme.u_type_primary"
            @click="tapFieldPress('idRecordDesc')"
          ></u-icon>
        </u-form-item>
        <u-form-item label="">
          <u-input
            type="textarea"
            :maxlength="maxLength"
            :disabled="!state.canEdit"
            v-model="queryRecordForm.idRecordDesc"
          />
        </u-form-item>
        <u-form-item label-width="auto" :border-bottom="false" label-position="left" label="告知陈述" prop="stmt" :required="isRequired">
          <u-icon
            slot="right"
            customPrefix="csbi-icon"
            name="moban"
            size="40"
            :color="$theme.u_type_primary"
            @click="tapFieldPress('stmt')"
          ></u-icon>
        </u-form-item>
        <u-form-item label="">
          <u-input
            type="textarea"
            :maxlength="maxLength"
            :disabled="!state.canEdit"
            v-model="queryRecordForm.stmt"
          />
        </u-form-item>
        <u-form-item label-width="auto" :border-bottom="false" label-position="left" label="询问内容" prop="askContent">
          <u-icon
            slot="right"
            customPrefix="csbi-icon"
            name="moban"
            size="40"
            :color="$theme.u_type_primary"
            @click="tapFieldPress('askContent')"
          ></u-icon>
        </u-form-item>
        <u-form-item label="">
          <u-input
            type="textarea"
            placeholder="请填写询问内容"
            :maxlength="maxLength"
            :disabled="!state.canEdit"
            v-model="queryRecordForm.askContent"
          />
        </u-form-item>
        <!-- 添加物品清单 -->
        <u-form-item label-position="top" label="">
          <goods-list-com
            :caseUuid="caseParam.caseUuid"
            :caseCode="caseParam.caseCode"
            :handleStatus="caseParam.handleStatus"
            :hasEdit="false"
            :hasAdd="state.canEdit"
            :height="400"
            :widthP="getWidth()"
            :showSearch="true"
            :params="params"
            ref="goodInfoRef"
          >
          </goods-list-com>
        </u-form-item>
      </u-form>
    </view>
    <!-- 底部按钮开始 -->
    <view class="submit-btns btn-other-cls" v-if="state.canEdit">
      <u-button plain class="u-btn" type="primary" @click="submitBtn('save')">
        保存
      </u-button>
      <u-button class="u-btn" type="primary" @click="submitBtn('submit')">
        提交
      </u-button>
    </view>
    <!-- 底部按钮结束 -->
    <!-- 人员选择 -->
    <u-popup mode="bottom" height="80%" v-model="personSelectShow">
      <person-selection :params="psParam" @choose="handlerChoosePerson"></person-selection>
    </u-popup>
    <u-picker mode="time" :params="paramsDate" v-model="isShowAskS" @confirm="changeDate('askTimeS',$event)">
    </u-picker>
    <u-picker mode="time" :params="paramsDate" v-model="isShowAskE" @confirm="changeDate('askTimeE',$event)">
    </u-picker>
    <u-popup mode="bottom" height="80%" v-model="partySelectShow">
      <select-party-component :params="partyParams" :isCheckBox="false" @choose="handlerChooseParty"></select-party-component>
    </u-popup>
    <u-popup mode="bottom" height="80%" v-model="showFieldTpl">
      <doc-form-content-tep
        :params="fieldParam"
        formName="queryRecordForm"
        :fieldkey="fieldKey"
        @choice="choiceFieldTpl"
      ></doc-form-content-tep>
    </u-popup>
    <!-- 下拉选择用 -->
    <dic-choice
      :keyWord="dicKeyWords"
      :currentSelect="dicCurrentSelect"
      v-model="dicShow"
      @confirm="selectDicConfirm"
    ></dic-choice>
  </view>
</template>

<script>
	import caseCommon from '../caseCommonMixin.js';
	import officeService from '@/service/case/office.service.js';
	import PersonSelection from '@/pages/case/components/personSelection.vue';
	import {
		IDENTITY_TYPE
	} from '@/common/common_enum.js';
	import DicChoice from '@/components/dic_choice.vue';
	import DicInput from '@/components/dic_input.vue';
	import moment from 'moment';
	import GoodsListCom from '../components/goodsListComponent.vue';
	import caseService from '@/service/case/case.service.js';
	import zjCommonService from '@/service/common/common.service';
	import SelectPartyComponent from '../components/selectPartyComponent.vue';
	import DocFormContentTep from '../components/docFormContentTemplate.vue';
	import FormSection from '@/components/form-section.vue';
	import {
		CASE_DOC_NAME_PATH
	} from '@/service/case/mapping/index.js';
	import {
		L_BSC_IDCARD_TYPE
	} from '@/service/intelligence/mapping/enum.js';
	import fabButton from '@/components/uni-fab.vue';

	export default {
		components: {
			PersonSelection,
			GoodsListCom,
			SelectPartyComponent,
			FormSection,
			DocFormContentTep,
			DicInput,
			DicChoice,
			fabButton
		},
		mixins: [caseCommon],
		data() {
			return {
				moment,
				IDENTITY_TYPE,
				paramsDate: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: true,
					timestamp: true,
				},
				border: false,
				errorType: ['border-bottom', 'message'],
				isRequired: true,
				labelWidth: '220',
				labelPosition: 'top',
				maxLength: 9999,
				isShowAskS: false,
				isShowAskE: false,
				isCanClick: false, // 是否可点击承办人按钮
				employeeLst: [], // 选择人员数据
				perFlag: '', // 选择人员类型 询问人or记录人
				caseParam: {}, // 上个页面传过来的参数
				queryRecordForm: {},
				doc: {},
				personSelectShow: false,
				psParam: {},
				goodsData: {}, // 物品数据
				baseInfo: {},
				params: {},
				orginalCaseClueList: [],
				// dic_select 是否显示
				dicShow: false,
				// dic 关键字
				dicKeyWords: '',
				// dic 当前选择项
				dicCurrentSelect: '',
				dicType: '',
				rules: {
					askTimeS: [{
						required: true,
						message: '请选择询问开始时间',
						trigger: ['change', 'blur'],
					}, ],
					handlingAddr: [{
						required: true,
						message: '请输入询问地点',
						trigger: ['change', 'blur'],
					}, ],
					askTimeE: [{
							required: true,
							message: '请选择询问结束时间',
							trigger: ['change', 'blur'],
						},
						{
							validator: (rule, value, callback) => {
								return this.queryRecordForm['askTimeE'] < this.queryRecordForm['askTimeS'] ? false : true;
							},
							message: '结束时间必须大于开始时间',
						},
					],
					askAddr: [{
							required: true,
							message: '请填写询问地点！',
							trigger: 'change',
						},
						{
							max: 50,
							message: '询问地点长度请输入50个字符之间！',
							trigger: 'change',
						},
					],
					askPerson: [{
						required: true,
						message: '请选择询问人',
						trigger: ['change', 'blur'],
					}, ],
					recordPerson: [{
						required: true,
						message: '请选择记录人',
						trigger: ['change', 'blur'],
					}, ],
					byAskPsn: [{
							required: true,
							message: '请输入被询问人',
							trigger: ['change', 'blur'],
						},
						{
							message: '姓名格式不正确！',
							trigger: ['change', 'blur'],
							validator: (rule, value, callback) => {
								if (this.$u.test.isEmpty(value)) {
									return true;
								} {
									let regs = /^[a-zA-Z\u4e00-\u9fa5]+$/;
									return regs.test(value);
								}
							},
						},
					],
					byAskSex: [{
						required: true,
						message: '请选择性别',
						trigger: ['change', 'blur'],
					}, ],
					byAskIdType: [{
						required: true,
						message: '请选择证件类型',
						trigger: ['change', 'blur'],
					}, ],
					byAskIdNo: [{
							required: true,
							message: '请输入证件号码',
							// 可以单个或者同时写两个触发验证方式
							trigger: ['change', 'blur'],
						},
						{
							message: '证件格式不正确！',
							trigger: ['change', 'blur'],
							validator: () => {
								if (this.queryRecordForm.byAskIdType == L_BSC_IDCARD_TYPE.IDCARD) {
									// 身份证号
									let regs =
										/(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}[0-9Xx]$)/;
									return regs.test(this.queryRecordForm.byAskIdNo);
								} else if (this.queryRecordForm.byAskIdType == L_BSC_IDCARD_TYPE.PASSPORT) {
									// 护照
									let regs = /(^[EeKkGgDdSsPpHh]\d{8}$)|(^(([Ee][a-fA-F])|([DdSsPp][Ee])|([Kk][Jj])|([Mm][Aa])|(1[45]))\d{7}$)/; // 护照（包括香港和澳门）
									return regs.test(this.queryRecordForm.byAskIdNo);
								} else if (this.queryRecordForm.byAskIdType == L_BSC_IDCARD_TYPE.OTHER) {
									// 其他证件
									let regs = /^[0-9a-zA-Z]*$/;
									return regs.test(this.queryRecordForm.byAskIdNo);
								} else if (this.queryRecordForm.byAskIdType == L_BSC_IDCARD_TYPE.DRIVER) {
									// 驾照
									let regs = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}(\d|x|X)$/;
									return regs.test(this.queryRecordForm.byAskIdNo);
								} else if (this.queryRecordForm.byAskIdType == L_BSC_IDCARD_TYPE.RESIDENCE_BOOKLET) {
									// 户口簿
									let regs = /^[a-zA-Z0-9]{3,21}$/;
									return regs.test(this.queryRecordForm.byAskIdNo);
								} else {
									return true;
								}
							},
						},
					],
					byAskNation: [{
						required: true,
						message: '请选择民族',
						trigger: ['change', 'blur'],
					}, ],
				        byAskAge: [
				          {
				            required: true,
				            message: "请输入年龄",
				            trigger: ["change", "blur"],
				          },
				        ],
					byAskHomeAddr: [{
						required: true,
						message: '请输入证件地址',
						trigger: ['change', 'blur'],
					}, ],
					byAskAddr: [{
						required: true,
						message: '请输入经营地址',
						trigger: ['change', 'blur'],
					}, ],
					byAskPhone: [{
							required: true,
							message: '请输入联系电话',
							trigger: ['change', 'blur'],
						},
						{
							message: '电话格式不正确！',
							trigger: ['change', 'blur'],
							validator: (rule, value, callback) => {
								return this.$u.test.mobile(value) || this.$u.test.tel(value);
							},
						},
					],
					idRecordDesc: [{
							required: true,
							message: '请输入表明身份记录',
							trigger: ['change', 'blur'],
						},
						{
							max: 200,
							message: '表明身份记录长度请输入200个字符之间！',
							trigger: 'change',
						},
					],
					stmt: [{
							required: true,
							message: '请输入告知陈述',
							trigger: ['change', 'blur'],
						},
						{
							max: 500,
							message: '告知陈述长度请输入500个字符之间！',
							trigger: 'change',
						},
					],
				},
				btnType: '',
				isReadBoolean: false,
				partySelectShow: false,
				partyNames: '', // 当事人名称
				partyList: [], // 当事人列表
				partyParams: {}, // 传给当事人选择页面的参数
				ifborder: false,
				fContent: [{
					iconPath: require('@/static/oview.png'),
					selectedIconPath: require('@/static/oview.png'),
					text: '预览',
					active: false,
				}],
				fContents: [{
					iconPath: require('@/static/dy.png'),
					selectedIconPath: require('@/static/dy.png'),
					text: '打印',
					active: false,
				}],
				// h5端部分浏览器input设置disabled后点击事件失效 2023-10-27 fsx start
				pointerStyle: {
					marginRight: "5px",
					pointerEvents: "none !important"
				},
				// h5端部分浏览器input设置disabled后点击事件失效 2023-10-27 fsx end
			};
		},
		watch: {
			isShowAskS(newValue, oldValue) {
				this.$refs.changeRefS.validation();
			},
			isShowAskE(newValue, oldValue) {
				this.$refs.changeRefE.validation();
			},
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		onLoad(preParams) {
			this.caseParam = this.getRouteParam();
			this.psParam.caseUuid = this.caseParam.caseUuid;
			caseService
				.getCaseInfoById({
					caseUuid: this.psParam.caseUuid,
				})
				.then((res) => {
					this.$modal.hideLoading();
					this.baseInfo = res.bean || {};
					this.getDefaultCaseClue();
				})
				.catch((res) => {
					this.$modal.hideLoading();
					this.$u.toast(res.msg);
				});
		},
		mounted() {
			this.docStep((docInfo) => {
				this.doc = docInfo;
				this.setRightBtns();
			});
			this.initDocData();
		},
		methods: {
			getDefaultCaseClue() {
				caseService
					.casePropertyList()
					.then((res) => {
						if (!res.success) {
							return;
						}
						if (res.data && res.data.length > 0) {
							if (this.baseInfo.casePropertyRelList && this.baseInfo.casePropertyRelList.length > 0) {
								this.orginalCaseClueList = [];
								for (let i = 0; i < this.baseInfo.casePropertyRelList.length; i++) {
									let op = this.baseInfo.casePropertyRelList[i];
									for (let j = 0; j < res.data.length; j++) {
										if (res.data[j].casepropUuid == op.casepropUuid) {
											let opx = res.data[j];
											this.objMerge(opx, op);
											this.orginalCaseClueList.push(opx);
											this.params.orginalCaseClueList = this.orginalCaseClueList;
											break;
										}
									}
								}
							}
						}
					})
					.catch((err) => {
						console.log('查询失败:' + err);
					});
			},
			dicSelectOpen(type, keyWords) {
				if (type == this.dicType) {
					if (this.dicKeyWords == keyWords && this.dicShow) {
						return true;
					}
					return false;
				}
			},
			showDic(key, cur, type) {
				if (!this.state.canEdit) return;
				if (this.dicShow) return;
				this.dicKeyWords = key;
				this.dicCurrentSelect = cur;
				this.dicShow = true;
				this.dicType = type;
			},
			addAskPsn() {
				if (this.state.canEdit) {
					this.partySelectShow = true;
				}
			},
			selectDicConfirm(e) {
				if (this.dicKeyWords == this.$u.dic.DIC_KEYS.BSC_GENDDER) {
					// 性别
					this.queryRecordForm.byAskSexName = e[0].label;
					this.queryRecordForm.byAskSex = e[0].extra.bcbCode;
				} else if (this.dicKeyWords == this.$u.dic.DIC_KEYS.IDCARD_TYPE) {
					// 证件类型
					this.queryRecordForm.byAskIdTypeName = e[0].label;
					this.queryRecordForm.byAskIdType = e[0].extra.bcbCode;
				} else if (this.dicKeyWords == this.$u.dic.DIC_KEYS.NATION_LIST) {
					// 民族
					this.queryRecordForm.byAskNationName = e[0].label;
					this.queryRecordForm.byAskNation = e[0].extra.bcbCode;
				}
			},
			initDocData() {
				this.$u.loading('加载中...');
				officeService
					.docFields(this.caseParam.docUuid, true)
					.then((docConfigs) => {
						if (docConfigs.success) {
							this.docFields = [...docConfigs.data];
							let parms = {
								id: this.caseParam.id,
								docUuid: this.caseParam.docUuid,
								bizUuid: this.caseParam.bizUuid,
							};
							// 获取询问笔录数据
							officeService
								.getDocAskRecord(parms)
								.then((res) => {
									this.$u.hideLoading();
									let [tiInfo, rs] = [{}, {}];
									if (res.success && res.data.length === 2) {
										tiInfo = res.data[0];
										rs = res.data[1];
										Object.keys(tiInfo).forEach((key) => {
											rs[key] = tiInfo[key];
										});
									} else {
										rs = res.data[0];
									}
									this.queryRecordForm = rs;
									this.getPartyInfoList();
								})
								.catch((er) => {
									console.log(er);
									this.$u.hideLoading();
									this.$u.toast(er);
								});
						} else {
							this.$u.toast(docConfigs.msg);
						}
					})
					.catch((er) => {
						console.log(er);
						this.$u.hideLoading();
						this.$u.toast(er);
					});
			},
			checkboxChange(e) {
				console.log(e);
				this.isReadBoolean = e;
				if (this.isReadBoolean) {
					this.queryRecordForm.isRead = 1;
				}
			},
			// 获取当事人list（单选）
			getPartyInfoList() {
				caseService
					.getPartyInfoList(this.caseParam.bizUuid)
					.then((res) => {
						if (!res.success) return;
						let names = [];
						let uuids = [];
						this.partyList = res.data.length > 0 ? res.data : [];
						this.partyList.forEach((itm) => {
							names.push(itm.partyName);
							uuids.push(itm.partyUuid);
							if (this.queryRecordForm.partyUuids === itm.partyUuid) {
								itm.check = true;
							}
						});
						this.partyParams = {
							list: this.partyList,
							selUsersStr: this.queryRecordForm.partyUuids,
						};
					})
					.catch((err) => {
						this.partyList = [];
						console.log(err);
					});
			},
			// 选择当事人回调事件
			handlerChooseParty(e) {
				this.partySelectShow = false;
				this.queryRecordForm.byAskPsn = e.partyNames;
				this.partyParams.selUsersStr = e.partyUuids;
				this.queryRecordForm.partyUuids = e.partyUuids;
				this.queryRecordForm.byAskNation = e.list[0].nation; // 民族
				this.queryRecordForm.byAskSex = e.list[0].partyType; // 性别
				this.queryRecordForm.byAskPhone = e.list[0].phone; // 联系电话
				this.queryRecordForm.byAskIdType = e.list[0].idCardType; // 证件类型
				this.queryRecordForm.byAskIdNo = e.list[0].idCard; // 证件号码
      				this.queryRecordForm.byAskAddr = e.list[0].busiAddr; // 经营地址
				this.queryRecordForm.byAskHomeAddr = e.list[0].idCardAddr; // 证件地址
      				this.queryRecordForm.byAskAge = e.list[0].age; // 年龄
				this.$forceUpdate();
			},
			// 查询案件物品信息表
    getGoodsList() {
      officeService.caseGoodsPunishList(this.caseParam.caseUuid).then(res => {
        if (res.success) {
          let num = 0;
          let amt = 0.00;
          let sellNum = 0;
          let sellAmt = 0.00;
          res.data && res.data.forEach(g => {
            num += g.qty;
            amt += g.amt;
            sellNum += (g.illegalQty || 0);
            sellAmt += (g.illegalAmt || 0);
          });
          this.goodsData = {
            list: res.data,
            goodsUnitNum: parseFloat(num.toFixed(2)),
            goodsAmt: parseFloat(amt.toFixed(2)),
            sellNum: parseFloat(sellNum.toFixed(2)),
            sellAmt: parseFloat(sellAmt.toFixed(2)),
          }
          console.log(this.goodsData.list);
        }
      });

    },
			// 设置右侧标题
			setRightBtns() {
				// #ifdef H5-DINGDING
				this.$deviceApi.setRight(this.state.canEdit ? '预览' : '打印', () => {
					this.printOrDown(this.state.canEdit);
					this.setRightBtns();
				}, true, true);
				// #endif
			},
			fabtrigger(btn) {
				if (btn.index == 0) {
					this.printOrDown(this.state.canEdit);
				}
			},
			// 打印/预览
			printOrDown(flag) {
				if (flag) {
					// 调接口预览
					this.submitDocInfo('preview');
				} else {
					this.downloadFile(this.doc.pdfFileId);
				}
			},
			downloadFile(fileId, titleName, isDownload) {
				let pdfIds = fileId;
				if (!pdfIds) {
					this.$u.toast('没有文书');
					return;
				}
				this.setRouteParam({
					fileId: pdfIds,
					fileName: titleName,
					isDownload: isDownload,
					isSign: CASE_DOC_NAME_PATH[this.doc?.configIns?.docCode]?.isSign,
				});
				this.$u.route('pages/commonPage/printerComponent');
			},
			clickDateBtn(type) {
				this[type] = true;
			},
			// 表单验证
			validForm(type) {
				let basicValid = false;
				this.btnType = type;
				this.$refs.uForm.validate((valid) => {
					if (valid) {
						if (!this.queryRecordForm.partyUuids) {
							this.$u.toast('请选择当事人!');
							return;
						}
						basicValid = true;
						console.log('表单验证通过');
					} else {
						basicValid = false;
						console.log('表单验证失败');
					}
				});
				return basicValid;
			},
			submitBtn(type) {
				// 点击提交、保存按钮
				let flag = this.validForm(type);
				if (flag) {
					if (type == 'submit') {
						this.$modal.confirm('完成后不可修改，请确认是否填写完整准确无误？', () => {
							this.submitDocInfo(type);
						});
					} else {
						this.submitDocInfo(type);
					}
				}
			},
			submitDocInfo(type) {
				// 保存/提交
				let {
					id,
					docUuid,
					titemUuid
				} = this.caseParam;
				this.queryRecordForm.caseUuid = this.psParam.caseUuid;
				this.$u.loading('数据保存中...');
				this.$set(this.queryRecordForm, 'fullDocNo', this.queryRecordForm.byAskPsn);
				officeService.saveDocAskRecord(this.queryRecordForm, docUuid, titemUuid, id, this.caseParam.type).then((res) => {
					this.$u.hideLoading();
					if (res.success) {
						this.queryRecordForm = {
							...this.queryRecordForm,
							...res.bean,
						};
						try {
							if (!this.doc) this.doc = res.data[0];
						} catch (e) {
							console.log(e);
						}
						if (type == 'submit') {
							this.$u.loading('数据提交中...');
							officeService.submitDocAskRecord(this.queryRecordForm, docUuid, titemUuid, id, this.caseParam.type).then((res) => {
								this.$u.hideLoading();
								this.$u.toast(res.msg);
								this.saveBehaviorLog(1, this.caseParam, this.doc);
								if (res.success) {
									this.backPrev({
										paramKey: 'offiList',
										param: {
											caseUuid: this.caseParam.bizUuid,
											caseCode: this.caseParam.caseCode,
											caseType: this.caseParam.caseType,
										},
									});
								}
							});
						} else if (type == 'preview') {
							this.$u.loading('生成PDF中...');
							officeService.buildLocalPunish('/survey/doc-ask-record', this.doc.docInsUuid).then((pdfId) => {
								this.$u.hideLoading();
								if (pdfId.success) {
									this.downloadFile(pdfId.bean, '预览', false);
								} else {
									this.$u.toast(pdfId.msg);
								}
							});
						} else {
							this.saveBehaviorLog(0, this.caseParam, this.doc);
							this.$u.toast(res.msg);
						}
					} else {
						this.$u.hideLoading();
						this.$u.toast(res.msg);
					}
				});
			},
			// 添加询问人和记录人
			addUndertaker(flag) {
				if (flag == 'aPer') {
					this.psParam.min = 2;
					delete this.psParam.max;
				} else {
					this.psParam.max = 1;
					delete this.psParam.min;
				}
				this.perFlag = flag;
				this.personSelectShow = true;
			},
			// 选择执行人（询问人、记录人）
			handlerChoosePerson(e) {
				this.personSelectShow = false;
				this.employeeLst = [...e];
				let tIds = [];
				let tNames = [];
				this.employeeLst.forEach((el) => {
					tIds.push(el.personUuid);
					tNames.push(el.personName);
				});
				if (this.perFlag == 'aPer') {
					this.queryRecordForm['askPersonUuids'] = tIds.join(',');
					this.queryRecordForm['askPerson'] = tNames.join(',');
				} else {
					this.queryRecordForm['recordPerson'] = tNames.join(',');
				}
			},
			changeDate(type, e) {
				this.queryRecordForm[type] = this.$u.date(e.timestamp, 'yyyy年mm月dd日 hh时MM分');
			},
			getWidth() {
				let w = this.$u.sys().windowWidth - 32 + 'px';
				console.log('=====' + w);
				return w;
			},
			updateBackState(param) {
				console.log(param);
				this.$refs['goodInfoRef'].updateBackState(param);
			},
		},
	};
</script>

<style lang="scss" scoped>
	@import '../case_common.scss';

	.page {
		padding: 0;
	}
</style>
